package Dome1;


public class Text1 extends Object{
    public static void main(String[] args) throws CloneNotSupportedException {
        Student wang = new Student("wang", 21);
        Student student= (Student) wang.clone();
        System.out.println(wang);
        System.out.println(student);
        System.out.println("=======================");
        wang.money.m=100;
        System.out.println(wang);
        System.out.println(student);


    }

}
class Student implements Cloneable{
    String name;
    int age;
    Money money=new Money();
    public Student(String name, int age) {
        this.name = name;
        this.age = age;

    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", money=" + money.m +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student tmp=(Student)super.clone();
            tmp.money=(Money) tmp.money.clone();
            return tmp;
    }
}


class Money implements Cloneable{
    public double m = 99.99;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
